<script>
// const requestUrl = "http://123.57.200.119:8090/the-little-princess/"
const requestUrl = "http://localhost:8011/time-axis/";
const version = 1.3;

const crystalsUrl = 'https://patchwiki.biligame.com/images/gt/thumb/6/6d/fzs06t1prgxyn6kw58a9ya71dsd6lyf.png/20px-%E8%8B%B1%E9%9B%84%E6%B0%B4%E6%99%B6.png';

function isLatestVersion() {
  let localVersion = lGet('version');
  console.log('localVersion->' + localVersion + ",version->" + version);
  if (isNull(localVersion) || localVersion < version) {
    clearData();
    lSet('version', version);
    return false;
  }
  return true;
}

function isRememberMe(flag) {
  lSet('rememberMe', flag);
}

// function getRememberMe() {
//     return lGet('rememberMe');
// }

function rememberMe() {
  let rememberMe = lGet('rememberMe');
  if (isNull(rememberMe)) {
    isRememberMe(true);
    rememberMe = true;
  }
  return rememberMe === 'true';
}

function loginUser() {
  if (rememberMe())
    return JSON.parse(lGet('loginUser'));
  else
    return JSON.parse(sGet('loginUser'));
}

function setLoginUser(userInfo) {
  let userInfoJson = JSON.stringify(userInfo)
  if (rememberMe())
    lSet('loginUser', userInfoJson);
  else
    sSet('loginUser', userInfoJson);
}


function clearData() {
  sessionStorage.removeItem('loginUser');
  localStorage.removeItem('loginUser');
}

function lSet(key, value) {
  localStorage.setItem(key, value);
}

function lGet(key) {
  return localStorage.getItem(key);
}

function sSet(key, value) {
  sessionStorage.setItem(key, value);
}

function sGet(key) {
  return sessionStorage.getItem(key);
}

function isNull(obj) {
  return obj === undefined || obj === null;
}

function copyValue(obj) {
  return JSON.parse(JSON.stringify(obj));
}

export default {
  requestUrl,
  rememberMe,
  loginUser,
  isRememberMe,
  // getRememberMe,
  crystalsUrl,
  setLoginUser,
  isLatestVersion,
  lSet,
  lGet,
  sSet,
  sGet,
  isNull,
  clearData,
  copyValue
}
</script>
